﻿package mortal.game.view.guide.guideUse
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.button.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.forging.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuideEquipUseWin extends GuideUseWinBase
    {
        protected var _txtDesc:GTextFiled;
        protected var _txtName:GTextFiled;
        protected var _txtEquipName:GTextFiled;
        protected var _txtAdd:BitmapNumberText;
        protected var _btnEquip:GLabelButton;
        protected var _comBatSp:GSprite;
        protected var _myEquip:ItemData;
        private var _isEquipTransfer:Boolean;

        public function GuideEquipUseWin(param1:ILayer = null)
        {
            super(param1);
            return;
        }// end function

        override protected function updateData() : void
        {
            var _loc_1:int = 0;
            var _loc_2:* = new ItemData(_itemData.serverData);
            this._txtName.htmlText = _itemData.itemInfo.htmlName;
            var _loc_3:int = 0;
            this._myEquip = Cache.instance.pack.packRolePackCache.getEquipByType(_itemData.itemInfo.type);
            if (this._myEquip != null)
            {
                _loc_3 = EquipmentUtil.getEquipCombat(this._myEquip);
                this._txtEquipName.htmlText = Language.getStringByParam(20999, ItemsUtil.getItemWholeName(this._myEquip, true));
                if (!this._isEquipTransfer)
                {
                    _loc_2.extInfo = this._myEquip.extInfo.clone();
                }
            }
            else
            {
                this._txtEquipName.htmlText = Language.getStringByParam(20999, Language.getString(21000));
            }
            _loc_1 = EquipmentUtil.getEquipCombat(_loc_2);
            if (this._myEquip != null && _loc_1 > _loc_3)
            {
                this._txtAdd.text = (_loc_1 - _loc_3).toString();
            }
            else
            {
                this._txtAdd.text = _loc_1.toString();
            }
            if (this.isShouldReplace())
            {
                this._btnEquip.label = ImagesConst.GuideEquipLabel_Change;
                this._txtDesc.text = Language.getString(35316);
            }
            else
            {
                this._btnEquip.label = ImagesConst.GuideEquipLabel_PutOn;
                if (this._isEquipTransfer)
                {
                    this._txtDesc.text = Language.getString(35317);
                }
                else
                {
                    this._txtDesc.text = Language.getString(35318);
                }
            }
            return;
        }// end function

        override protected function timerOut() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.useItemHandler(null);
            return;
        }// end function

        private function isShouldReplace() : Boolean
        {
            return this._myEquip && _itemData && EquipmentUtil.compareStrengLevel(this._myEquip, _itemData) > 0;
        }// end function

        override protected function updatePos() : void
        {
            super.updatePos();
            if (this._comBatSp && this._txtAdd && this._txtAdd.text)
            {
                this._comBatSp.x = (this.width - (this._txtAdd.x + 14 * this._txtAdd.text.length)) / 2;
                this._comBatSp.y = 95;
            }
            if (this._txtEquipName)
            {
                this._txtEquipName.y = 130;
            }
            if (this._btnEquip)
            {
                this._btnEquip.y = this.height - this._btnEquip.height - 12 + _windowBg.y;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._comBatSp = UICompomentPool.getUICompoment(GSprite);
            this._comBatSp.x = 80;
            this.addChild(this._comBatSp);
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.CombatTxt, 0, 0, this._comBatSp));
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.AttrUpIcon, 60, 2, this._comBatSp));
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            this._txtDesc = UIFactory.gTextField("", 40, 36, 220, 40, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatBai.center();
            this._txtName = UIFactory.gTextField("", 37, 67, 220, 20, this, _loc_1);
            _loc_1 = GlobalStyle.textFormatBai.center();
            this._txtEquipName = UIFactory.gTextField("", 37, 130, 220, 20, this, _loc_1);
            this._txtAdd = UIFactory.bitmapNumberText(80, 0, "GuideItemUseNum.png", 16, 20, -2, this._comBatSp);
            this._btnEquip = UIFactory.gLabelButton(ImagesConst.GuideEquipLabel_PutOn, GLabelButton.gLoadingButton, ResFileConst.TaskContinue, 95, 130, 103, 40, this, "GImageBitmap");
            this._btnEquip.configEventListener(MouseEvent.CLICK, this.useItemHandler);
            return;
        }// end function

        public function set isEquipTransfer(param1:Boolean) : void
        {
            this._isEquipTransfer = param1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._txtAdd.dispose(param1);
            this._txtDesc.dispose(param1);
            this._txtName.dispose(param1);
            this._txtEquipName.dispose(param1);
            this._comBatSp.dispose(param1);
            this._btnEquip.dispose(param1);
            this._txtAdd = null;
            this._txtDesc = null;
            this._txtName = null;
            this._txtEquipName = null;
            this._comBatSp = null;
            this._btnEquip = null;
            this._myEquip = null;
            this._isEquipTransfer = false;
            super.disposeImpl(param1);
            return;
        }// end function

        protected function useItemHandler(event:MouseEvent) : void
        {
            disposeTimer();
            var _loc_2:* = _item.localToGlobal(GameConst.yellowPoint);
            FlyToNavbarTool.flyBitmapOriginalToPack(_item.bitmapdata, _loc_2, ModuleType.Players);
            ForgingConst.IsGuideUseEquip = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Equip, _item.itemData));
            this.hide();
            return;
        }// end function

    }
}
